package com.falcon.controller.log;

import com.falcon.mvc.domain.BaseResponse;
import com.falcon.mvc.domain.PagerResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

import com.falcon.domain.dos.LogDO;
import com.falcon.domain.req.LogQuery;
import com.falcon.domain.req.LogRequest;
import com.falcon.service.ILogService;

@Slf4j
@RestController
@RequestMapping("/log/log")
@Tag(name = "LogController", description = "日志表-接口")
public class LogController {

    @Autowired
    private ILogService logService;

    @Operation(summary = "新增")
    @PostMapping()
    public BaseResponse<Long> save(@Valid @RequestBody LogRequest request) {

        Long id =  this.logService.save(request);

        return BaseResponse.success(id);
    }

    @Operation(summary = "修改")
    @PutMapping("/{id}")
    public BaseResponse<Boolean> update(@PathVariable Long id, @Valid @RequestBody LogRequest request) {

        Boolean success =  this.logService.update(id, request);

        return BaseResponse.success(success);
    }

    @Operation(summary = "删除")
    @DeleteMapping("/{id}")
    public BaseResponse<Boolean> delete(@PathVariable Long id) {

        Boolean success =  this.logService.deleteById(id);

        return BaseResponse.success(success);
    }

    @Operation(summary = "查询基本信息")
    @GetMapping("/{id}")
    public BaseResponse<LogDO> info(@PathVariable Long id) {

        LogDO userDO =  this.logService.queryById(id);

        return BaseResponse.success(userDO);
    }


    @Operation(summary = "列表查询")
    @PostMapping("/list")
    public BaseResponse<List<LogDO>> list(@RequestBody LogQuery request) {

        List<LogDO> list =  this.logService.queryList(request);

        return BaseResponse.success(list);
    }

    @Operation(summary = "分页查询")
    @PostMapping("/pager")
    public PagerResponse<LogDO> pager(@RequestBody LogQuery request) {

        PagerResponse<LogDO> pager =  this.logService.queryPager(request);

        return pager;
    }


}

